﻿using System;
using System.Configuration;
using System.ServiceModel.Configuration;

namespace Motar.ServiceModel.Configuration
{

    /// <summary>
    /// 
    /// </summary>
    public class CookieBehaviorExtensionElement : BehaviorExtensionElement
    {

        /// <summary>
        /// 
        /// </summary>
        public override Type BehaviorType
        {
            get { return typeof(CookieEndpointBehavior); }
        }

        /// <summary>
        /// 
        /// </summary>
        [ConfigurationProperty("resolvingKey")]
        public string ResolvingKey { get { return (string)this["resolvingKey"]; } set { this["resolvingKey"] = value; } }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected override object CreateBehavior()
        {
            string key = ResolvingKey;

            if (string.IsNullOrEmpty(key))
            {
                return new CookieEndpointBehavior();
            }
            else
            {
                return new CookieEndpointBehavior(key);
            }
        }
    }
}
